let storageHandler = localStorage
const SessionStorage = {
  writeObject(key, object) {
    if (object instanceof Object || object instanceof Array) {
      storageHandler[key] = JSON.stringify(object)
    } else {
      storageHandler[key] = object
    }
  },
  readObject(key) {
    let text = storageHandler[key]
    if (text) {
      try {
        return JSON.parse(text)
      } catch (e) {
        console.warn('Read object is not json string')
      }
    }
    return text
  },
  readValue(key) {
    return storageHandler[key]
  }
}

export {SessionStorage as default}
